package com.byzx.wine.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;








import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;








import com.byzx.wine.service.ISyauthorityService;
import com.byzx.wine.service.ISyroleauthorityService;
import com.byzx.wine.service.SyuserServices;

@Controller
@RequestMapping(value = "/ztree")
public class ztreeAction {
	// @Resource(name = "SyuserServiceImpl")
	@Autowired
	private SyuserServices syuserService;
	@Autowired
	private ISyauthorityService  syauthorityService;
	
	@Autowired
	private ISyroleauthorityService syroleauthorityService;
	
	

	@RequestMapping(value = "/ztree1")
	@ResponseBody
	public List<Map<String, Object>> ztree(Integer id) {
		return syuserService.selectAll(id);
		
	}

	@RequestMapping(value = "/ztree2")
	@ResponseBody
	public Map<String, Object> shouquan(Integer id, String ids) {
		System.out.println(ids + "+++++" + id);
		Integer sy = syuserService.shouquan(id, ids);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("b", sy);
		return map;
	}

	
	//查询用户权限  
		@RequestMapping("/findUserSyauthority")
		@ResponseBody
		public List<Map<String ,Object> > findUserSyauthority(HttpServletRequest request){
	
		    HttpSession session=request.getSession();
		    String name=(String) session.getAttribute("username");
			List<Map<String ,Object>> list=syauthorityService.findUserSyauthority(name);
			return list;
		}

		
		
		//角色授权role
		@RequestMapping("/ztree3")
		@ResponseBody
		public Map<String, Object> selectAuthority(Integer roleid){
			List<Map<String, Object>> list = syroleauthorityService.Syroleauthority(roleid);
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("list", list);
			return map;
		}
		
		
		@RequestMapping("/ztree4")
		@ResponseBody
		public Map<String, Object> authorityDeal(Integer roleid,String ids){
			 Integer s =syroleauthorityService.dealAuthority(roleid, ids);
			 Map<String, Object> map = new HashMap<String, Object>();
			 map.put("s ", s );
			return map;
		}
		
	}


